<%@ page import="com.space.entity.User" %>
<%--
  Created by IntelliJ IDEA.
  User: 20064
  Date: 2020/2/16
  Time: 10:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户信息</title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 字体 -->
    <%--    <link href="https://fonts.font.im/css?family=Ruslan+Display" rel="stylesheet">--%>

    <!-- 图标 -->
    <link rel="icon" type="image/png" sizes="144x144" href="../images/airplane.png"/>
    <link rel="apple-touch-icon" type="image/png" sizes="144x144" href="../images/airplane.png"/>

    <!-- 其他 -->
    <link rel="stylesheet" href="../js/bootstrap-4.4.1-dist/css/bootstrap.min.css">

    <!-- js -->
    <script type="text/javascript" src="../js/jquery-3.4.1/jquery-3.4.1.js"></script>
</head>
<body>
<%
    User user = (User) session.getAttribute("userLogin");
    if (user == null) {
        response.sendRedirect("index.jsp");
    }
    assert user != null;
%>

<div class="container">
    <div class="row">
        <div class="card shadow w-100">
            <div class="card-header">
                <h2>个人资料</h2>
            </div>
            <div class="card-body">
                <table class="table table-hover">
                    <tbody>
                    <tr>
                        <td class="text-right"><strong>用户ID:</strong></td>
                        <td class="text-center">
                            <mark>
                                <%=user.getUserId()%>
                            </mark>
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="text-right"><strong>用户账号:</strong></td>
                        <td class="text-center">
                            <mark>
                                <%=user.getUserAccount()%>
                            </mark>
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="text-right"><strong>用户手机号:</strong></td>
                        <td class="text-center">
                            <mark>
                                <%=user.getUserPhone()%>
                            </mark>
                        </td>
                        <td>
                            <button class="btn btn-primary" type="button" data-toggle="modal" data-target="#myModal">
                                修改
                            </button>
                        </td>
                    </tr>
                    <tr>
                        <td class="text-right"><strong>用户密码:</strong></td>
                        <td class="text-center">
                            <mark>
                                <%=user.getUserPwd()%>
                            </mark>
                        </td>
                        <td>
                            <button class="btn btn-primary" type="button" onclick="changePWd()">修改</button>
                        </td>
                    </tr>
                    <tr>
                        <td class="text-right"><strong>用户状态:</strong></td>
                        <td class="text-center">
                            <mark>
                                <%=user.getUserStatus().getStatusTypeName()%>
                            </mark>
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="card-footer">
                <div class="w-100 ">
                    <button class="btn btn-warning text-white float-right" type="button" onclick="goBack()">返回</button>
                </div>
            </div>
            <!-- 模态框 -->
            <div class="modal fade" id="myModal">
                <div class="modal-dialog">
                    <div class="modal-content">

                        <!-- 模态框头部 -->
                        <div class="modal-header">
                            <h4 class="modal-title">修改手机号</h4>
                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                        </div>

                        <!-- 模态框主体 -->
                        <div class="modal-body">
                            <form action="changeUserPhone.do" method="post">
                                <div class="form-group">
                                    <label for="userPhone">新手机号</label>
                                    <input type="text" class="form-control" name="userPhone" id="userPhone">
                                </div>
                                <input type="hidden" name="userId" value="<%=user.getUserId()%>">
                                <button class="btn btn-info" type="submit">修改</button>
                            </form>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>

</div>

</body>
<script type="text/javascript" src="../js/bootstrap-4.4.1-dist/js/bootstrap.min.js"></script>
<script type="text/javascript">
    function changePWd() {
        location.href = "forgetPwd.jsp";
    }

    function goBack() {
        location.href = "index.jsp";
    }

    $("form").submit(function () {
        var phone = $("#userPhone").val();
        if (!/^1\d{10}$/.test(phone)) {
            alert("请输入正确的手机号");
            return false;
        }
        if (!checkUserPhone()) {
            return false;
        }
    });

    function checkUserPhone() {
        var check = false;
        $.ajax({
            async: false,
            url: "checkUserPhone.do",
            type: "post",
            data: {userId: $("input[name='userId']").val(), userPhone: $("input[name='userPhone']").val()},
            dataType: "json",
            success: function (result) {
                check = result.check;
                if (!check) {
                    alert(result.msg);
                }
            }
        });
        return check;
    }
</script>
</html>
